//
// SoapTrace.Net - A soap message monitoring utility. 
//
// Copyright (C) 2005 Matthew Ward
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Matthew Ward (mrward@users.sourceforge.net)

using System;
using System.Net;
using System.Net.Sockets;

namespace SoapTrace.Core.Communication
{
	/// <summary>
	/// Interface that a socket must implement.
	/// </summary>
	/// <remarks>
	/// Main use of this interface is to use a mock Socket object
	/// for testing.</remarks>
	public interface ISocket
	{
		/// <summary>
		/// Closes the socket connection and releases all associated 
		/// resources.
		/// </summary>
		void Close( );
		
		/// <summary>
		/// Establishes a connection to a remote host.
		/// </summary>
		/// <param name="remoteEP">An end point that represents
		/// the remote device.</param>
		void Connect( EndPoint remoteEP );

		/// <summary>
		/// Determines the status of the Socket.
		/// </summary>
		/// <param name="microSeconds">The time to wait for a response, in 
		/// microseconds.</param>
		/// <param name="mode">One of the <see cref="SelectMode"/> 
		/// values. </param>
		bool Poll( int microSeconds, SelectMode mode );
		
		/// <summary>
		/// Receives data from a bound Socket into a receive buffer.
		/// </summary>
		/// <param name="buffer">An array of type Byte that is the storage 
		/// location for the received data.
		/// </param>
		/// <returns>The number of bytes received.</returns>
		int Receive( byte[ ] buffer );

		/// <summary>
		/// Disables sends and receives on a socket.
		/// </summary>
		/// <param name="how">One of the SocketShutdown values that specifies 
		/// the operation that will no longer be allowed. </param>
		void Shutdown( SocketShutdown how );

		/// <summary>
		/// Gets the remote endpoint
		/// </summary>
		EndPoint RemoteEndPoint { get; }
		
		/// <summary>
		/// Gets the local endpoint
		/// </summary>
		EndPoint LocalEndPoint { get; }
		
		/// <summary>
		/// Sends data to a connected Socket.
		/// </summary>
		/// <param name="buffer">An array of of type Byte that contains 
		/// the data to be sent. </param>
		int Send( byte[ ] buffer );
	}
}
